<form id="form1" method="post">
	<input name="id" id="id" class="mini-hidden" value="0"/>
	<input name="types" id="types" class="mini-hidden" value="0"/>
	<div style="padding-left:11px;padding-bottom:5px;">
		<table style="table-layout:fixed;">
			<tr>
				<td style="width:70px;">名称：</td>
				<td style="width:150px;"><input name="name" id="name" class="mini-textbox" required="true" style="width:100%;"/></td>
				<td style="width:70px;">负责人：</td>
				<td style="width:150px;">
					<div name="contact" id="contact" class="mini-combobox" popupWidth="350" popupHeight="100" textField="name" valueField="id" multiSelect="true" style="width:100%;">     
					    <div property="columns">
					        <div header="编号" field="id" width="50px"></div>
					        <div header="名称" field="name" width="100px"></div>
					        <div header="职位" field="position" width="100px"></div>
					    </div>
					</div>
					<!--  
					<input name="contact" id="contact" class="mini-buttonedit" onbuttonclick="onButtonEdit(this,'/common/staff')" style="width:100%;"/>
					-->
				</td>
			</tr>
			<tr>
				<td style="width:70px;">电话：</td>
				<td style="width:150px;"><input name="tel" id="tel" class="mini-textbox" required="true" vtype="minLength:8" style="width:100%;"/></td>
				<td style="width:70px;">工单确认：</td>
				<td style="width:150px;"><input name="status" id="status" class="mini-combobox" textField="name" valueField="name" data="[{name:'是'},{name:'否'}]" allowInput="true" style="width:100%;" /></td>
			</tr>
			<tr>
				<td style="width:70px;">业务范围：</td>
				<td style="width:380px;" colspan="3">
					<div name="business" id="business" class="mini-combobox" popupWidth="250" popupHeight="100" textField="name" valueField="id" multiSelect="true" style="width:100%;">     
					    <div property="columns">
					        <div header="编号" field="name" width="160px"></div>
					    </div>
					</div>
				</td>
			</tr>
			<tr>
				<td style="width:70px;">地址：</td>
				<td style="width:380px;" colspan="3"><input name="addres" id="addres" class="mini-textbox" required="true" style="width:100%;"/></td>
			</tr>
			<tr>
				<td style="width:70px;">描述：</td>
				<td style="width:380px;" colspan="3"><input name="desc" id="desc" class="mini-textarea" style="width:100%;" emptyText="请输入描述"/></td>
			</tr>
		</table>
	</div>
	<div style="text-align:center;padding:10px;">   
		<a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>   
		<a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>   
	</div>
</form>
<script type="text/javascript">
mini.parse();

var form = new mini.Form("form1");

function SaveData() {
	form.validate();
	if (form.isValid() == false) return;
	//mini.get("contact").setValue(mini.get("contact").getText());
	$.ajax({
		type:"POST",
		url:"/basic/agencyAdd",
		data:{data:form.getData()},
		cache: false,
		success: function (text) {
			CloseWindow("save");
		},
		error: function (jqXHR, textStatus, errorThrown) {
			CloseWindow();
		}
	});
}

function SetData(data) {
	mini.get("contact").load("/staff/getStaffList?id=" + data.id);
	mini.get("business").load("/basic/cost");
	if (data.action == "edit") {
		data = mini.clone(data);
		mini.get("types").setValue("edit");
		mini.get("id").setValue(data.id);
		mini.get("name").setValue(data.name);
		mini.get("status").setValue(data.status);
		mini.get("addres").setValue(data.addres);
		mini.get("contact").setValue(data.contact);
		mini.get("contact").setText(data.contact);
		mini.get("business").setValue(data.business);
		mini.get("business").setText(data.businesstext);
		mini.get("tel").setValue(data.tel);
		mini.get("desc").setValue(data.desc);
	}

	if (data.action == "new") {
		data = mini.clone(data);
		mini.get("types").setValue("new");
		mini.get("id").setValue(data.id);
		mini.get("business").setValue(data.business);
	}
}

function CloseWindow(action) {
	if (action == "close" && form.isChanged()) {
		if (confirm("数据被修改了，是否先保存？")) {
			return false;
		}
	}
	if (window.CloseOwnerWindow){
		return window.CloseOwnerWindow(action);
	}else{
		window.close();
	}
}

function onOk(e) {
	SaveData();
}
function onCancel(e) {
	CloseWindow("cancel");
}
</script>
